n=int(input())
n1=n//10
n2=n%1000
n3=n//100
n4=n2//10
n5=n%100
n6=n//1000
n7=n3%10
n8=n5//10
n9=n%10
y = 0
for k in range(2,int(n9**0.5)+1):
        if n9%k == 0:
            break
else:
    y=max(n9,y)
for k in range(2,int(n8**0.5)+1):
        if n8%k == 0:
            break
else:
    y=max(n8,y)
for k in range(2,int(n7**0.5)+1):
        if n7%k == 0:
            break
else:
    y=max(n7,y)
for k in range(2,int(n6**0.5)+1):
        if n6%k == 0:
            break
else:
    y=max(n6,y)
for k in range(2,int(n5**0.5)+1):
        if n5%k == 0:
            break
else:
    y=max(n5,y)
for k in range(2,int(n4**0.5)+1):
        if n4%k == 0:
            break
else:
    y=max(n4,y)
for k in range(2,int(n3**0.5)+1):
        if n3%k == 0:
            break
else:
    y=max(n3,y)
for k in range(2,int(n2**0.5)+1):
        if n2%k == 0:
            break
else:
    y=max(n2,y)
for k in range(2,int(n1**0.5)+1):
        if n1%k == 0:
            break
else:
    y=max(n1,y)
for k in range(2,int(n**0.5)+1):
        if n%k == 0:
            break
else:
    y=max(n,y)
print(y)
